home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / lynx-2.4 / WWW / Library / Implementation / HTAAUtil.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-28  |  11.7 KB  |  361 lines

  1. /*                                            Utilities for the Authorization parts of libwww
  2.              COMMON PARTS OF AUTHORIZATION MODULE TO BOTH SERVER AND BROWSER
  3.                                              
  4.    This module is the interface to the common parts of Access Authorization (AA) package
  5.    for both server and browser. Important to know about memory allocation:
  6.    
  7.    Routines in this module use dynamic allocation, but free automatically all the memory
  8.    reserved by them.
  9.    
  10.    Therefore the caller never has to (and never should) free() any object returned by
  11.    these functions.
  12.    
  13.    Therefore also all the strings returned by this package are only valid until the next
  14.    call to the same function is made. This approach is selected, because of the nature of
  15.    access authorization: no string returned by the package needs to be valid longer than
  16.    until the next call.
  17.    
  18.    This also makes it easy to plug the AA package in: you don't have to ponder whether to
  19.    free() something here or is it done somewhere else (because it is always done somewhere
  20.    else).
  21.    
  22.    The strings that the package needs to store are copied so the original strings given as
  23.    parameters to AA functions may be freed or modified with no side effects.
  24.    
  25.    Also note: The AA package does not free() anything else than what it has itself
  26.    allocated.
  27.    
  28.  */
  29.  
  30. #ifndef HTAAUTIL_H
  31. #define HTAAUTIL_H
  32.  
  33. #ifndef HTUTILS_H
  34. #include "HTUtils.h"            /* BOOL, PARAMS, ARGS */
  35. #endif /* HTUTILS_H */
  36. #include "tcp.h"
  37. #include "HTList.h"
  38.  
  39. #ifdef SHORT_NAMES
  40. #define HTAASenu        HTAAScheme_enum
  41. #define HTAASnam        HTAAScheme_name
  42. #define HTAAMenu        HTAAMethod_enum
  43. #define HTAAMnam        HTAAMethod_name
  44. #define HTAAMinL        HTAAMethod_inList
  45. #define HTAAteMa        HTAA_templateMatch
  46. #define HTAAmaPT        HTAA_makeProtectionTemplate
  47. #define HTAApALi        HTAA_parseArgList
  48. #define HTAAsuRe        HTAA_setupReader
  49. #define HTAAgUfL        HTAA_getUnfoldedLine
  50. #endif /*SHORT_NAMES*/
  51.  
  52.  
  53. /*
  54.  
  55. Default filenames
  56.  
  57.  */
  58. #ifndef PASSWD_FILE
  59. #define PASSWD_FILE     "/home2/luotonen/passwd"
  60. #endif
  61.  
  62. #ifndef GROUP_FILE
  63. #define GROUP_FILE      "/home2/luotonen/group"
  64. #endif
  65.  
  66. #define ACL_FILE_NAME   ".www_acl"
  67.  
  68.  
  69. /*
  70. ** Numeric constants
  71. */
  72. #define MAX_USERNAME_LEN        16      /* @@ Longest allowed username    */
  73. #define MAX_PASSWORD_LEN        3*13    /* @@ Longest allowed password    */
  74.                                         /* (encrypted, so really only 3*8)*/
  75. #define MAX_METHODNAME_LEN      12      /* @@ Longest allowed method name */
  76. #define MAX_FIELDNAME_LEN       16      /* @@ Longest field name in       */
  77.                                         /* protection setup file          */
  78. #define MAX_PATHNAME_LEN        80      /* @@ Longest passwd/group file   */
  79.                                         /* patname to allow               */
  80.  
  81. /*
  82. ** Helpful macros
  83. */
  84. #define FREE(x) if (x) {free(x); x=NULL;}
  85.  
  86. /*
  87.  
  88. Datatype definitions
  89.  
  90.   HTAASCHEME
  91.   
  92.    The enumeration HTAAScheme represents the possible authentication schemes used by the
  93.    WWW Access Authorization.
  94.    
  95.  */
  96.  
  97. typedef enum {
  98.     HTAA_UNKNOWN,
  99.     HTAA_NONE,
  100.     HTAA_BASIC,
  101.     HTAA_PUBKEY,
  102.     HTAA_KERBEROS_V4,
  103.     HTAA_KERBEROS_V5,
  104.     HTAA_MAX_SCHEMES /* THIS MUST ALWAYS BE LAST! Number of schemes */
  105. } HTAAScheme;
  106.  
  107. /*
  108.  
  109.   ENUMERATION TO REPRESENT HTTP METHODS
  110.   
  111.  */
  112.  
  113. typedef enum {
  114.     METHOD_UNKNOWN,
  115.     METHOD_GET,
  116.     METHOD_PUT
  117. } HTAAMethod;
  118.  
  119. /*
  120.  
  121. Authentication Schemes
  122.  
  123.  */
  124.  
  125. /* PUBLIC                                               HTAAScheme_enum()
  126. **              TRANSLATE SCHEME NAME TO A SCHEME ENUMERATION
  127. ** ON ENTRY:
  128. **      name            is a string representing the scheme name.
  129. **
  130. ** ON EXIT:
  131. **      returns         the enumerated constant for that scheme.
  132. */
  133. PUBLIC HTAAScheme HTAAScheme_enum PARAMS((CONST char* name));
  134.  
  135.  
  136. /* PUBLIC                                               HTAAScheme_name()
  137. **                      GET THE NAME OF A GIVEN SCHEME
  138. ** ON ENTRY:
  139. **      scheme          is one of the scheme enum values:
  140. **                      HTAA_NONE, HTAA_BASIC, HTAA_PUBKEY, ...
  141. **
  142. ** ON EXIT:
  143. **      returns         the name of the scheme, i.e.
  144. **                      "none", "basic", "pubkey", ...
  145. */
  146. PUBLIC char *HTAAScheme_name PARAMS((HTAAScheme scheme));
  147.  
  148. /*
  149.  
  150. Methods
  151.  
  152.  */
  153.  
  154. /* PUBLIC                                                   HTAAMethod_enum()
  155. **              TRANSLATE METHOD NAME INTO AN ENUMERATED VALUE
  156. ** ON ENTRY:
  157. **      name            is the method name to translate.
  158. **
  159. ** ON EXIT:
  160. **      returns         HTAAMethod enumerated value corresponding
  161. **                      to the given name.
  162. */
  163. PUBLIC HTAAMethod HTAAMethod_enum PARAMS((CONST char * name));
  164.  
  165.  
  166. /* PUBLIC                                               HTAAMethod_name()
  167. **                      GET THE NAME OF A GIVEN METHOD
  168. ** ON ENTRY:
  169. **      method          is one of the method enum values:
  170. **                      METHOD_GET, METHOD_PUT, ...
  171. **
  172. ** ON EXIT:
  173. **      returns         the name of the scheme, i.e.
  174. **                      "GET", "PUT", ...
  175. */
  176. PUBLIC char *HTAAMethod_name PARAMS((HTAAMethod method));
  177.  
  178.  
  179. /* PUBLIC                                               HTAAMethod_inList()
  180. **              IS A METHOD IN A LIST OF METHOD NAMES
  181. ** ON ENTRY:
  182. **      method          is the method to look for.
  183. **      list            is a list of method names.
  184. **
  185. ** ON EXIT:
  186. **      returns         YES, if method was found.
  187. **                      NO, if not found.
  188. */
  189. PUBLIC BOOL HTAAMethod_inList PARAMS((HTAAMethod        method,
  190.                                      HTList *           list));
  191. /*
  192.  
  193. Match Template Against Filename
  194.  
  195.  */
  196.  
  197. /* PUBLIC                                               HTAA_templateMatch()
  198. **              STRING COMPARISON FUNCTION FOR FILE NAMES
  199. **                 WITH ONE WILDCARD * IN THE TEMPLATE
  200. ** NOTE:
  201. **      This is essentially the same code as in HTRules.c, but it
  202. **      cannot be used because it is embedded in between other code.
  203. **      (In fact, HTRules.c should use this routine, but then this
  204. **       routine would have to be more sophisticated... why is life
  205. **       sometimes so hard...)
  206. **
  207. ** ON ENTRY:
  208. **      template        is a template string to match the file name
  209. **                      agaist, may contain a single wildcard
  210. **                      character * which matches zero or more
  211. **                      arbitrary characters.
  212. **      filename        is the filename (or pathname) to be matched
  213. **                      agaist the template.
  214. **
  215. ** ON EXIT:
  216. **      returns         YES, if filename matches the template.
  217. **                      NO, otherwise.
  218. */
  219. PUBLIC BOOL HTAA_templateMatch PARAMS((CONST char * template,
  220.                                        CONST char * filename));
  221.  
  222.  
  223. /* PUBLIC                                               HTAA_templateCaseMatch()
  224. **              STRING COMPARISON FUNCTION FOR FILE NAMES
  225. **                 WITH ONE WILDCARD * IN THE TEMPLATE (Case Insensitive)
  226. ** NOTE:
  227. **      This is essentially the same code as in HTAA_templateMatch, but
  228. **      it compares case insensitive (for VMS). Reason for this routine
  229. **      is that HTAA_templateMatch gets called from several places, also
  230. **      there where a case sensitive match is needed, so one cannot just
  231. **      change the HTAA_templateMatch routine for VMS.
  232. **
  233. ** ON ENTRY:
  234. **      template        is a template string to match the file name
  235. **                      agaist, may contain a single wildcard
  236. **                      character * which matches zero or more
  237. **                      arbitrary characters.
  238. **      filename        is the filename (or pathname) to be matched
  239. **                      agaist the template.
  240. **
  241. ** ON EXIT:
  242. **      returns         YES, if filename matches the template.
  243. **                      NO, otherwise.
  244. */
  245. PUBLIC BOOL HTAA_templateCaseMatch PARAMS((CONST char * template,
  246.                                          CONST char * filename));
  247.  
  248.  
  249. /* PUBLIC                                       HTAA_makeProtectionTemplate()
  250. **              CREATE A PROTECTION TEMPLATE FOR THE FILES
  251. **              IN THE SAME DIRECTORY AS THE GIVEN FILE
  252. **              (Used by server if there is no fancier way for
  253. **              it to tell the client, and by browser if server
  254. **              didn't send WWW-ProtectionTemplate: field)
  255. ** ON ENTRY:
  256. **      docname is the document pathname (from URL).
  257. **
  258. ** ON EXIT:
  259. **      returns a template matching docname, and other files
  260. **              files in that directory.
  261. **
  262. **              E.g.  /foo/bar/x.html  =>  /foo/bar/ *
  263. **                                                  ^
  264. **                              Space only to prevent it from
  265. **                              being a comment marker here,
  266. **                              there really isn't any space.
  267. */
  268. PUBLIC char *HTAA_makeProtectionTemplate PARAMS((CONST char * docname));
  269. /*
  270.  
  271. MIME Argument List Parser
  272.  
  273.  */
  274.  
  275.  
  276. /* PUBLIC                                               HTAA_parseArgList()
  277. **              PARSE AN ARGUMENT LIST GIVEN IN A HEADER FIELD
  278. ** ON ENTRY:
  279. **      str     is a comma-separated list:
  280. **
  281. **                      item, item, item
  282. **              where
  283. **                      item ::= value
  284. **                             | name=value
  285. **                             | name="value"
  286. **
  287. **              Leading and trailing whitespace is ignored
  288. **              everywhere except inside quotes, so the following
  289. **              examples are equal:
  290. **
  291. **                      name=value,foo=bar
  292. **                       name="value",foo="bar"
  293. **                        name = value ,  foo = bar
  294. **                         name = "value" ,  foo = "bar"
  295. **
  296. ** ON EXIT:
  297. **      returns a list of name-value pairs (actually HTAssocList*).
  298. **              For items with no name, just value, the name is
  299. **              the number of order number of that item. E.g.
  300. **              "1" for the first, etc.
  301. */
  302. PUBLIC HTList *HTAA_parseArgList PARAMS((char * str));
  303.  
  304. /*
  305.  
  306. Header Line Reader
  307.  
  308.  */
  309.  
  310. /* PUBLIC                                               HTAA_setupReader()
  311. **              SET UP HEADER LINE READER, i.e. give
  312. **              the already-read-but-not-yet-processed
  313. **              buffer of text to be read before more
  314. **              is read from the socket.
  315. ** ON ENTRY:
  316. **      start_of_headers is a pointer to a buffer containing
  317. **                      the beginning of the header lines
  318. **                      (rest will be read from a socket).
  319. **      length          is the number of valid characters in
  320. **                      'start_of_headers' buffer.
  321. **      soc             is the socket to use when start_of_headers
  322. **                      buffer is used up.
  323. ** ON EXIT:
  324. **      returns         nothing.
  325. **                      Subsequent calls to HTAA_getUnfoldedLine()
  326. **                      will use this buffer first and then
  327. **                      proceed to read from socket.
  328. */
  329. PUBLIC void HTAA_setupReader PARAMS((char *     start_of_headers,
  330.                                      int        length,
  331.                                      int        soc));
  332.  
  333.  
  334. /* PUBLIC                                               HTAA_getUnfoldedLine()
  335. **              READ AN UNFOLDED HEADER LINE FROM SOCKET
  336. ** ON ENTRY:
  337. **      HTAA_setupReader must absolutely be called before
  338. **      this function to set up internal buffer.
  339. **
  340. ** ON EXIT:
  341. **      returns a newly-allocated character string representing
  342. **              the read line.  The line is unfolded, i.e.
  343. **              lines that begin with whitespace are appended
  344. **              to current line.  E.g.
  345. **
  346. **                      Field-Name: Blaa-Blaa
  347. **                       This-Is-A-Continuation-Line
  348. **                       Here-Is_Another
  349. **
  350. **              is seen by the caller as:
  351. **
  352. **      Field-Name: Blaa-Blaa This-Is-A-Continuation-Line Here-Is_Another
  353. **
  354. */
  355. PUBLIC char *HTAA_getUnfoldedLine NOPARAMS;
  356.  
  357. #endif  /* NOT HTAAUTIL_H */
  358. /*
  359.  
  360.    End of file HTAAUtil.h. */
  361.